package com.wonders.hisdoctor.station.project.hisqueue.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wonders.hisdoctor.station.constant.ServiceConstant;
import com.wonders.hisdoctor.station.project.base.domain.HospitalDict;
import com.wonders.hisdoctor.station.project.base.mapper.HospitalDictMapper;
import com.wonders.hisdoctor.station.project.hisqueue.domain.DiagnosisExplain;
import com.wonders.hisdoctor.station.project.hisqueue.service.IDiagnosisExplainService;
import com.wonders.hisdoctor.station.project.hisqueue.mapper.DiagnosisExplainMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 诊断说明书表 服务类
 * </p>
 *
 * @author zhanghaonan
 * @since 2021/06/21
 */
@Service
public class DiagnosisExplainServiceImpl extends ServiceImpl<DiagnosisExplainMapper, DiagnosisExplain> implements IDiagnosisExplainService {

    @Autowired
    private DiagnosisExplainMapper diagnosisExplainMapper;

    @Autowired
    private HospitalDictMapper hospitalDictMapper;

    @Override
    public DiagnosisExplain saveAndPrint(DiagnosisExplain diagnosisExplain) {
        //登记日期取当天
        diagnosisExplain.setRegisterDate(new Date());
        //查询是否存在，不存在则新增，否则更新
        DiagnosisExplain result = this.baseMapper.selectById(diagnosisExplain);
        if (result == null) {
            this.baseMapper.insert(diagnosisExplain);
        } else {
            diagnosisExplainMapper.updateByPrimaryKey(diagnosisExplain);
        }
        return diagnosisExplain;
    }

    @Override
    public HospitalDict selectHospitalByCode(String hospitalCode) {
        return hospitalDictMapper.selectOne(new QueryWrapper<HospitalDict>().eq(ServiceConstant.HOSPITAL_CODE, hospitalCode));
    }
}
